package com.class05.statics;

import com.class05.Calculator;

/**
 * @ClassDescription: 代理类[中介]
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/10/31 19:52
 */
public class StaticProxyCalculator implements Calculator {
    private Calculator calculator;

    //    使用构造函数传入目标
    public StaticProxyCalculator(Calculator target) {
        this.calculator = target;
    }

    @Override
    public int add(int i, int j) {
//        非核心业务  中介使用
        System.out.println("i = " + i + ", j = " + j);
//        调用目标
        int result = calculator.add(i, j);
        System.out.println("result = " + result);
        return result;
    }

    @Override
    public int sub(int i, int j) {
        //        非核心业务  中介使用
        System.out.println("i = " + i + ", j = " + j);
//        调用目标
        int result = calculator.sub(i, j);
        System.out.println("result = " + result);
        return result;
    }

    @Override
    public int mul(int i, int j) {
        //        非核心业务  中介使用
        System.out.println("i = " + i + ", j = " + j);
//        调用目标
        int result = calculator.mul(i, j);
        System.out.println("result = " + result);
        return result;
    }

    @Override
    public int div(int i, int j) {
        //        非核心业务  中介使用
        System.out.println("i = " + i + ", j = " + j);
//        调用目标
        int result = calculator.div(i, j);
        System.out.println("result = " + result);
        return result;
    }
}
